<template>
  <div id="app">
    <router-view />
    <theme-picker @change="themeChange"/>
  </div>
</template>
<script>
import ThemePicker from '@/components/ThemePicker'
import actions from '@/cros/actions'

export default {
  name: 'App',
  components: { ThemePicker },
  mounted () {
    const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
    actions.onGlobalStateChange((state, prevState) => {
      this.$store.dispatch('settings/changeSetting', {
        key: 'theme',
        value: state.settings || storageSetting.theme
      })
    }, true)
  },
  methods: {
    themeChange (val) {
      this.$store.dispatch('settings/changeSetting', {
        key: 'theme',
        value: val
      })
    }
  }
}
</script>
<style scoped>
#app .theme-picker {
  display: none;
}
</style>
